﻿using FAMailUtils;
using FAMailUtils.Data.DAO;
using FAMailUtils.Data.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineBusinesses
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["EmailLogin"] = null;
            Session["UserLogin"] = null;
        }
        AccountDAO utils = new AccountDAO();
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            UserLoginDTO user = utils.GetUserLogin(txtEmail.Text, txtPass.Text);
            if (user != null)
            {
                Session["EmailLogin"] = user.UserType == UserType.CustomerAccount ? user.Client.Email : user.UserName;
                Session["UserLogin"] = user;

                if (Request.QueryString["url"] + "" != "")
                    Response.Redirect(Request.QueryString["url"] + "", false);

                if (user.UserType != UserType.SystemAccount)
                Response.Redirect("areas/customeradmin/default.aspx", false);
                else
                    Response.Redirect("areas/systemadmin/default.aspx", false);
            }
            else {
                lblError.Text = "Email đăng nhập hoặc mật khẩu không hợp lệ!"; lblError.Visible = true;
                return;
            }
        }
    }
}